from geopy.distance import geodesic


def get_bounding_box(lat, lon, radius_km):
    """
    获取给定经纬度点周围指定半径的矩形区域的四个角点

    :param lat: 经度
    :param lon: 纬度
    :param radius_km: 半径（公里）
    :return: (min_lat, min_lon, max_lat, max_lon)
    """
    origin = (lat, lon)

    # 向北移动 radius_km 公里
    north = geodesic(kilometers=radius_km).destination(origin, 0)

    # 向南移动 radius_km 公里
    south = geodesic(kilometers=radius_km).destination(origin, 180)

    # 向东移动 radius_km 公里
    east = geodesic(kilometers=radius_km).destination(origin, 90)

    # 向西移动 radius_km 公里
    west = geodesic(kilometers=radius_km).destination(origin, 270)

    min_lat = min(north.latitude, south.latitude)
    max_lat = max(north.latitude, south.latitude)
    min_lon = min(east.longitude, west.longitude)
    max_lon = max(east.longitude, west.longitude)

    return (min_lat, min_lon, max_lat, max_lon)


# 示例使用
lat = 39.9042  # 北京的纬度
lon = 116.4074  # 北京的经度
radius_km = 3  # 3公里

(min_lat, min_lon, max_lat, max_lon) = get_bounding_box(lat, lon, radius_km)
print(f"西南角: ({min_lat}, {min_lon})")
print(f"东北角: ({max_lat}, {max_lon})")